package com.star.star.Activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.star.star.R;
import com.star.star.bean.CircleBean;
import com.star.star.bean.CircleRightBean;
import com.star.star.utils.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import static android.widget.GridLayout.VERTICAL;

public class circleActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv_main_title, tv_back;
    private RecyclerView rv_left, rv_right;
    private List<CircleBean> daBeans = new ArrayList<>();
    private List<CircleRightBean> rightBeans = new ArrayList<>();

    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cicle);
        tv_back = findViewById(R.id.tv_back);
        tv_main_title = findViewById(R.id.tv_main_title);
        tv_main_title.setText("发现新圈子");
        tv_back.setOnClickListener(this);
        rv_left = findViewById(R.id.rv_left);
        rv_right = findViewById(R.id.rv_right);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(VERTICAL);
        rv_left.setLayoutManager(layoutManager);
        daBeans.add(new CircleBean("推荐"));
        daBeans.add(new CircleBean("韩国明星"));
        daBeans.add(new CircleBean("华语明星"));
        daBeans.add(new CircleBean("兴趣"));
        daBeans.add(new CircleBean("资讯"));
        buylistdapter adapte = new buylistdapter(this);
        rv_left.setAdapter(adapte);
        adapte.notifyDataSetChanged();

        LinearLayoutManager layoutManager2 = new LinearLayoutManager(this);
        layoutManager2.setOrientation(VERTICAL);
        rv_right.setLayoutManager(layoutManager2);
        String image = "https://img.ixiumei.com/uploadfile/2019/1206/20191206101927751.jpg";
        rightBeans.add(new CircleRightBean(image,"鹿晗","131万",false));
        rightBeans.add(new CircleRightBean(image,"路少女","31万",false));
        rightBeans.add(new CircleRightBean(image,"张一山","1311万",false));
        rightBeans.add(new CircleRightBean(image,"及你太美","11万",false));
        rightBeans.add(new CircleRightBean(image,"吴亦凡","231万",false));
        rightBeans.add(new CircleRightBean(image,"大碗面","131万",false));
        rightlistdapter adaptea = new rightlistdapter(this, rightBeans);
        rv_right.setAdapter(adaptea);
        adaptea.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back:
                finish();
                break;
        }
    }

    public class buylistdapter extends RecyclerView.Adapter<buylistdapter.MYholder> {
        private int mMposition;
        private Context context;

        public buylistdapter(Context context) {
            this.context = context;
        }

        @Override
        public MYholder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(circleActivity.this).inflate(R.layout.circle_left_adapter_item, parent, false);
            return new MYholder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MYholder holder, int position) {
            holder.tv_d_name.setText(daBeans.get(position).getName());
            if (position == mMposition) {
                holder.tv_d_name.setTextColor(context.getResources().getColor(R.color.colorAccent));
            } else {
                holder.tv_d_name.setTextColor(context.getResources().getColor(R.color.c_000000));
            }
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mMposition = holder.getAdapterPosition();
                    notifyDataSetChanged();
                }
            });
        }


        @Override
        public int getItemCount() {
            return daBeans.size();
        }

        private class MYholder extends RecyclerView.ViewHolder {

            private final TextView tv_d_name;

            public MYholder(View view) {
                super(view);
                tv_d_name = view.findViewById(R.id.tv_d_name);
            }

        }
    }

    public class rightlistdapter extends RecyclerView.Adapter<rightlistdapter.MYholder> {
        private Context context;

        public rightlistdapter(Context context, List<CircleRightBean> rightBeans) {
            this.context = context;
        }

        @Override
        public MYholder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(circleActivity.this).inflate(R.layout.circle_right_adapter_item, parent, false);
            return new MYholder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MYholder holder, int position) {
            if (rightBeans.get(position).isF()==true){
                holder.tv_clock.setText("已关注");
            }else {
                holder.tv_clock.setText("关注");
            }
            Glide.with(context).load(rightBeans.get(position).getImage()).into(holder.iv_image);
            holder.tv_name.setText(rightBeans.get(position).getName());
            holder.tv_number.setText(rightBeans.get(position).getNum());
            holder.tv_clock.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if ( rightBeans.get(position).isF()==true){
                        rightBeans.get(position).setF(false);
                    }else {
                        rightBeans.get(position).setF(true);
                    }
                    notifyDataSetChanged();
                }
            });
        }


        @Override
        public int getItemCount() {
            return rightBeans.size();
        }

        private class MYholder extends RecyclerView.ViewHolder {

            private final TextView tv_name,tv_number,tv_clock;
            private final CircleImageView iv_image;

            public MYholder(View view) {
                super(view);
                tv_clock = view.findViewById(R.id.tv_clock);
                tv_number = view.findViewById(R.id.tv_number);
                tv_name = view.findViewById(R.id.tv_name);
                iv_image = view.findViewById(R.id.iv_image);
            }

        }
    }
}
